package com.fingard.avatar.website.model.bean;

import com.fingard.avatar.website.model.enums.ResultCode;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * @author 徐一涛
 * @date 2022/4/26
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Accessors(chain = true)
public class ResultContext<T> extends BaseResultContext {
    private T data;

    public static <T> ResultContext<T> success(T data) {
        ResultContext<T> t = new ResultContext<>();
        t.setData(data);
        t.setCode(ResultCode.SUCCESS.getValue());
        t.setSuccess(true);
        return t;
    }

    public static ResultContext<Void> fail(ResultCode code, String info) {
        ResultContext<Void> t = new ResultContext<>();
        t.setInfo(info);
        t.setCode(code.getValue());
        t.setSuccess(false);
        return t;
    }

}
